﻿Imports System.Data
Imports System.Data.SqlClient
Partial Class Admin_frmTabState
    Inherits System.Web.UI.Page
    Dim conn As New SqlString()
    Dim _BO As New Bo()
    Dim _StateVO As New StateVo()
    Dim _EmployeeId As String
    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Try
            _StateVO.CountryId = ddlCountry.SelectedValue
            _StateVO.StateId = txtStateId.Text
            _StateVO.StateName = txtStateName.Text
            _BO.InsertState(_StateVO)
            ClearAll()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
 
    Sub GridData()
        Dim dtState As DataTable
        dtState = _BO.getStateDetails()
        gdState.DataSource = dtState
        gdState.DataBind()
    End Sub
    Public Sub ClearAll()
        ddlCountry.SelectedIndex = 0
        txtStateName.Text = ""
        txtStateId.Text = ""
        MsgBox("State inserted")
    End Sub
    Protected Sub gdState_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles gdState.EditCommand
        Session("EmpId") = _EmployeeId
        Response.Redirect("frmModifyState.aspx?StateId=" & e.Item.Cells(1).Text)
    End Sub
    Protected Sub gdState_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles gdState.DeleteCommand
        _BO.DeleteState(e.Item.Cells(1).Text)
        Response.Redirect("frmTabState.aspx")
    End Sub
    Protected Sub ImageAdd_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageAdd.Click
        panel2.Visible = True
        panel4.Visible = False
    End Sub

    Protected Sub ImageEdit_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageEdit.Click
        panel2.Visible = False
        panel4.Visible = True
        GridData()
    End Sub
    Protected Sub gdState_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles gdState.PageIndexChanged
        gdState.CurrentPageIndex = e.NewPageIndex
        GridData()
    End Sub
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        _EmployeeId = Session("EmpId")
        If _EmployeeId = "" Then
            Response.Redirect("../Client/frmLogin.aspx")
        End If
       
        If Page.IsPostBack = False Then
            panel2.Visible = False
            panel4.Visible = False
            GridData()
            CountryData()
        End If
    End Sub
    Public Sub CountryData()
        Dim dtCountry As DataTable
        dtCountry = _BO.getcountry()
        ddlCountry.DataSource = dtCountry
        ddlCountry.DataValueField = dtCountry.Columns(0).ToString
        ddlCountry.DataTextField = dtCountry.Columns(1).ToString
        ddlCountry.DataBind()
    End Sub

    Protected Sub btnReset_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReset.Click
        txtStateName.Text = ""
        txtStateId.Text = ""
    End Sub
End Class
